package com.changgou.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.pojo.CategoryBrand;
import com.changgou.service.CategoryBrandService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 品牌分类关联控制层
 *
 * @author gaofeng
 * @date 2025/4/20 10:51
 */
@Api(value = "CategoryBrandController")
@RestController
@RequestMapping("/categoryBrand")
@CrossOrigin
public class CategoryBrandController {
    @Resource
    private CategoryBrandService categoryBrandService;

    /**
     * CategoryBrand分页条件搜索实现
     *
     * @param categoryBrand 查询条件
     * @param page          当前页
     * @param size          每页显示条数
     * @return CategoryBrand
     */
    @ApiOperation(value = "CategoryBrand条件分页查询", notes = "分页条件查询CategoryBrand方法详情", tags = {"CategoryBrandController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}")
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "CategoryBrand对象", value = "传入JSON数据") CategoryBrand categoryBrand, @PathVariable int page, @PathVariable int size) {
        return new Result<>(true, StatusCode.OK, "查询成功", categoryBrandService.findPage(categoryBrand, page, size));
    }

    /**
     * CategoryBrand分页搜索实现
     *
     * @param page 当前页
     * @param size 每页显示多少条
     * @return CategoryBrand
     */
    @ApiOperation(value = "CategoryBrand分页查询", notes = "分页查询CategoryBrand方法详情", tags = {"CategoryBrandController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}")
    public Result<PageInfo> findPage(@PathVariable int page, @PathVariable int size) {
        PageInfo<CategoryBrand> pageInfo = categoryBrandService.findPage(page, size);
        return new Result<>(true, StatusCode.OK, "查询成功", pageInfo);
    }

    /**
     * 多条件搜索品牌数据
     *
     * @param categoryBrand 品牌分类查询条件
     * @return 品牌分类集合
     */
    @ApiOperation(value = "CategoryBrand条件查询", notes = "条件查询CategoryBrand方法详情", tags = {"CategoryBrandController"})
    @PostMapping(value = "/search")
    public Result<List<CategoryBrand>> findList(@RequestBody(required = false) @ApiParam(name = "CategoryBrand对象", value = "传入JSON数据") CategoryBrand categoryBrand) {
        List<CategoryBrand> list = categoryBrandService.findList(categoryBrand);
        return new Result<>(true, StatusCode.OK, "查询成功", list);
    }

    /**
     * 根据ID删除品牌数据
     *
     * @param id 品牌数据主键
     * @return 响应结果
     */
    @ApiOperation(value = "CategoryBrand根据ID删除", notes = "根据ID删除CategoryBrand方法详情", tags = {"CategoryBrandController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        categoryBrandService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    /**
     * 修改CategoryBrand数据
     *
     * @param categoryBrand 品牌分类查询条件
     * @param id            品牌数据主键
     * @return 响应结果
     */
    @ApiOperation(value = "CategoryBrand根据ID修改", notes = "根据ID修改CategoryBrand方法详情", tags = {"CategoryBrandController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value = "/update/{id}")
    public Result update(@RequestBody @ApiParam(name = "CategoryBrand对象", value = "传入JSON数据") CategoryBrand categoryBrand, @PathVariable Integer id) {
        categoryBrand.setCategoryId(id);
        categoryBrandService.update(categoryBrand);
        return new Result(true, StatusCode.OK, "修改成功");
    }

    /**
     * 新增CategoryBrand数据
     *
     * @param categoryBrand 品牌分类查询条件
     * @return 响应结果
     */
    @ApiOperation(value = "CategoryBrand添加", notes = "添加CategoryBrand方法详情", tags = {"CategoryBrandController"})
    @PostMapping(value = "/add")
    public Result add(@RequestBody @ApiParam(name = "CategoryBrand对象", value = "传入JSON数据", required = true) CategoryBrand categoryBrand) {
        categoryBrandService.add(categoryBrand);
        return new Result(true, StatusCode.OK, "添加成功");
    }

    /**
     * 根据ID查询CategoryBrand数据
     *
     * @param id 品牌数据主键
     * @return 品牌信息
     */
    @ApiOperation(value = "CategoryBrand根据ID查询", notes = "根据ID查询CategoryBrand方法详情", tags = {"CategoryBrandController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/findById、{id}")
    public Result<CategoryBrand> findById(@PathVariable Integer id) {
        CategoryBrand categoryBrand = categoryBrandService.findById(id);
        return new Result<>(true, StatusCode.OK, "查询成功", categoryBrand);
    }

    /**
     * 查询CategoryBrand全部数据
     *
     * @return 品牌分类集合
     */
    @ApiOperation(value = "查询所有CategoryBrand", notes = "查询所CategoryBrand有方法详情", tags = {"CategoryBrandController"})
    @GetMapping(value = "/findAll")
    public Result<List<CategoryBrand>> findAll() {
        List<CategoryBrand> list = categoryBrandService.findAll();
        return new Result<>(true, StatusCode.OK, "查询成功", list);
    }
}
